import Vue from 'vue'
import Router from 'vue-router'
import store from '../store'
Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [

  {
    path: '/login/index',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: '/dashboard',
      name: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '殡葬服务', icon: 'dashboard' }
    }]
  },
  {
    path: '/service',
    component: Layout,
    redirect: '/home',
    name: 'service',
    meta: { title: '殡仪馆服务办理', icon: 'tree' },
    children: [
      {
        path: '/home',
        name: 'home',
        component: () => import('@/views/service/home'),
        meta: { title: '火化档案', icon: 'table' }
      },
      {
        path: '/Service',
        name: 'Service',
        component: () => import('@/views/service/Service'),
        meta: { title: '服务洽谈', icon: 'table' }
      },
      {
        path: '/TotalMoney',
        name: 'TotalMoney',
        component: () => import('@/views/service/TotalMoney'),
        meta: { title: '费用结算', icon: 'table' }
      },
      {
        path: '/PrintReplace',
        name: 'PrintReplace',
        component: () => import('@/views/service/PrintReplace'),
        meta: { title: '火化证打印补办', icon: 'table' }
      },
      {
        path: '/PhotoArchival',
        name: 'PhotoArchival',
        component: () => import('@/views/service/PhotoArchival'),
        meta: { title: '拍照备案', icon: 'table' }
      },
      {
        path: '/DayPayment',
        name: 'DayPayment',
        component: () => import('@/views/service/DayPayment'),
        meta: { title: '费用日结/交账', icon: 'table' }
      }
    ]
  },
  {
    path: '/business',
    redirect: '/FileManagement',
    name: 'business',
    meta: { title: '殡仪馆业务办理', icon: 'tree' },
    children: [
      {
        path: '/FileManagement',
        name: 'FileManagement',
        component: () => import('@/views/business/FileManagement'),
        meta: { title: '火化档案查询', icon: 'table' }
      },
      {
        path: '/Costquery',
        name: 'Costquery',
        component: () => import('@/views/business/Costquery'),
        meta: { title: '费用查询', icon: 'table' }
      },
      {
        path: '/RevenueStatistics',
        name: 'RevenueStatistics',
        component: () => import('@/views/business/RevenueStatistics'),
        meta: { title: '殡仪馆收入查询', icon: 'table' }
      },
      {
        path: '/PreferentialRelief',
        name: 'PreferentialRelief',
        component: () => import('@/views/business/PreferentialRelief'),
        meta: {title: '优惠减免统计报表', icon: 'table'}
      },
      {
        path: '/CremationData',
        name: 'CremationData',
        component: () => import('@/views/business/CremationData'),
        meta: { title: '火化数据查询', icon: 'table' }
      },
      {
        path: '/CremationLedger',
        name: 'CremationLedger',
        component: () => import('@/views/business/CremationLedger'),
        meta: { title: '火化台账查询', icon: 'table' }
      },
      {
        path: '/Refrigeration',
        name: 'Refrigeration',
        component: () => import('@/views/business/Refrigeration'),
        meta: { title: '冷藏业务查询', icon: 'table' }
      },
      {
        path: '/CeremonyHall',
        name: 'CeremonyHall',
        component: () => import('@/views/business/CeremonyHall'),
        meta: { title: '礼厅业务查询', icon: 'table' }
      },
      {
        path: '/Overview',
        name: 'Overview',
        component: () => import('@/views/business/Overview'),
        meta: { title: '殡仪馆实时业务总览', icon: 'table' }
      },
      {
        path: '/CremationRecord',
        name: 'CremationRecord',
        component: () => import('@/views/datastatistics/CremationRecord'),
        meta: { title: '殡仪火化记录统计', icon: 'table' }
      },
      {
        path: '/ServiceSale',
        name: 'ServiceSale',
        component: () => import('@/views/datastatistics/ServiceSale'),
        meta: { title: '业务销售统计', icon: 'table' }
      },
      {
        path: '/Exemption',
        name: 'Exemption',
        component: () => import('@/views/datastatistics/Exemption'),
        meta: { title: '减免统计', icon: 'table' }
      },
      {
        path: '/RemainsCremationType',
        name: 'RemainsCremationType',
        component: () => import('@/views/datastatistics/RemainsCremationType'),
        meta: { title: '遗体火化类型统计', icon: 'table' }
      },
      {
        path: '/costSettlement',
        name: 'costSettlement',
        component: () => import('@/views/feesSettlement/costSettlement'),
        meta: { title: '费用结算', icon: 'table' }
      },
      {
        path: '/printCremation',
        name: 'printCremation',
        component: () => import('@/views/feesSettlement/printCremation'),
        meta: { title: '火化证打印', icon: 'table' }
      },
      {
        path: '/replacePrintCremation',
        name: 'replacePrintCremation',
        component: () => import('@/views/cremationCertificateReplace/replacePrintCremation'),
        meta: { title: '火化证打印补打', icon: 'table' }
      },
    ]
  },
  {
    path: '/setting',
    component: Layout,
    redirect: '/SystemSetup',
    name: 'setting',
    meta: { title: '系统设置与监控', icon: 'tree' },
    children: [
      {
        path: '/SystemSetup',
        name: 'SystemSetup',
        component: () => import('@/views/setting/SystemSetup'),
        meta: { title: '系统设置', icon: 'table' }
      },
      {
        path: '/DatabaseBackup',
        name: 'DatabaseBackup',
        component: () => import('@/views/setting/DatabaseBackup'),
        meta: { title: '数据库备份监控', icon: 'table' }
      },
      {
        path: '/SystemLog',
        name: 'SystemLog',
        component: () => import('@/views/setting/SystemLog'),
        meta: { title: '系统日志', icon: 'table' }
      }
    ]
  },
  // {
  //   path: '/receiving',
  //   component: Layout,
  //   redirect: '/SystemSetup',
  //   name: 'receiving',
  //   meta: { title: '殡仪馆车辆预约', icon: 'tree' },
  //   children: [
  //     {
  //       path: '/CarReservation',
  //       name: 'CarReservation',
  //       component: () => import('@/views/receiving/CarReservation'),
  //       meta: { title: '系统设置', icon: 'table' }
  //     },

  //   ]
  // },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]
export const whilteRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  }
]

 const createRouter = () => new Router({
  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: whilteRoutes
})

const router = createRouter()

router.$addRoutes = (params) => {
  router.matcher = new Router({mode: 'history'}).matcher
  router.addRoutes(params)

}
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
